package com.azt.provider.impl;

import com.azt.api.pojo.LevelUser;
import com.azt.api.service.LevelUserService;
import com.azt.model.page.Pagination;
import com.azt.provider.mapper.LevelUserMapper;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 用户成长值管理
 * Created by LiQZ on 2017/4/13.
 */
@Service
public class LevelUserServiceImpl implements LevelUserService {

    @Autowired
    private LevelUserMapper levelUserMapper;

    @Override
    public Pagination listPage(int pageNo, int pageSize, Map<String, String> params) {
        Page<Object> startPage = PageHelper.startPage(pageNo, pageSize);
        PageHelper.orderBy("createtime desc");
        List<LevelUser> list = levelUserMapper.selectByCondition(params);
        Pagination p = new Pagination(startPage, list);
        p.setList(list);
        return p;
    }

    @Override
    public int get(Integer type, Integer companyId) {
        Integer value = levelUserMapper.selectValue(companyId, type);
        return value == null? 0 : value;
    }

    @Override
    public LevelUser get(Integer companyId) {
        LevelUser user = new LevelUser();
        user.setCompanyId(companyId);
        return levelUserMapper.selectOne(user);
    }
}
